package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dto.GroupEntityDto;
import com.zhangtai.modules.entity.system.OrgGroupEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-08-10 16:30:24
 */
@Mapper
public interface OrgGroupDao extends BaseMapper<OrgGroupEntity> {


    @Select(
            "<script>" +
                    "Select org_id from sys_org_group   " +

                    "<where>" +
                    "<if test='groupIds!=null and groupIds.size>0'> group_id in " +
                    " <foreach item=\"groupId\" index=\"index\" collection=\"groupIds\" open=\"(\" separator=\",\" close=\")\">#{groupId}</foreach>" +
                    "</if>" +
                    "<if test='groupIds.size==0'> group_id = null</if>"+
                    "</where>" +
                    "  group by org_id" +
                    "</script>"
    )
    public List<Long> getOrgIdsByGroup(@Param("groupIds")List<Long> groupIds) ;


    //根据公司组id 查询公司id
    @Select("Select org_id from sys_org_group  where  group_id= #{beOrgGroupID} group by org_id " )
    public List<Long> getOrgIdsByGroupId(@Param("beOrgGroupID")Long beOrgGroupID) ;

    @Delete("select org_id FROM sys_org_group WHERE group_name = #{groupName}")
    public Long selectOrgGroupByName(String groupName);

	@Delete("DELETE FROM sys_org_group WHERE group_id = #{groupId}")
	public void deleteOrgGroup(Long groupId);

    @Select("Select group_id,group_name FROM sys_org_group where is_delete='0' and group_name like '%${groupName}%' GROUP BY group_id,group_name ")
    public List<GroupEntityDto> getOrgGroupPage(@Param("groupName") String groupName,Page<GroupEntityDto> page);

    @Select("Select group_id,group_name FROM sys_org_group where is_delete='0' GROUP BY group_id,group_name ")
    public List<GroupEntityDto> getOrgGroupList();

    @Select("Select * FROM sys_org_group where is_delete='0' and group_id = #{groupId}")
    public List<OrgGroupEntity> getOrgGroupInfo(@Param("groupId") Long groupId);




}
